/**
 * 
 */
package Server;

import java.util.*;
import java.beans.*;
import java.io.*;

/**
 * @author ronenkat
 *
 */
public class Listing {

	/**
	 * @param listOfFiles
	 */
	public Listing(Map<String, ListingEntry> listOfFiles) {
		super();
		this.listOfFiles = listOfFiles;
	}

	/**
	 */
	public Listing() {
		super();
		this.listOfFiles = new HashMap<String,ListingEntry>();
	}

	private Map<String,ListingEntry> listOfFiles;   
	//Vector<ListingEntry> listOfFiles;

	/**
	 * @return the listOfFiles
	 */
	public Map<String, ListingEntry> getListOfFiles() {
		return listOfFiles;
	}

	/**
	 * @param listOfFiles the listOfFiles to set
	 */
	public void setListOfFiles(Map<String, ListingEntry> listOfFiles) {
		this.listOfFiles = listOfFiles;
	}

	/**
	 * Write the backup server meta information repository to disk
	 * @param filename
	 * @param listing
	 * @throws FileNotFoundException 
	 */
	public static void writeListing(String filename, Listing listing) throws FileNotFoundException {
		XMLEncoder e;
		e = new XMLEncoder(
				new BufferedOutputStream(
						new FileOutputStream(filename)));

		e.writeObject( listing );
		e.close(); 
	}

	/**
	 * Read the backup server meta information repository from disk
	 * @param filename
	 * @return
	 * @throws FileNotFoundException 
	 */
	public static Listing readListing(String filename) throws FileNotFoundException {
		XMLDecoder d;
		d = new XMLDecoder(new BufferedInputStream(
				new FileInputStream(filename)));

		return (Listing)d.readObject();
	}
}
